package com.healthcarex.hip.saas.message.handler;


import org.w3c.dom.Node;

import java.lang.reflect.Field;

public class DefaultValueHandler extends AbstractValueHandler {

    @Override
    public Object getReadingValue(Object srcValue, String destType,
                                  String destFormat) {
        return srcValue;
    }

    @Override
    public String getWritingValue(Object srcValue, String destFormat) {
        return srcValue.toString();
    }

    @Override
    public void getNodeValue(Node node, Field field, Object obj) throws Exception {
        String value = node.getTextContent();
        field.set(obj, value == null ? "" : value);
    }

    @Override
    public void updateNodeValue(Node node, Field field, Object obj) throws Exception {
        Object value = field.get(obj);
        node.setTextContent(value == null ? "" : String.valueOf(value));
    }

    @Override
    public void setNodeValue(Node node, Field field, Object obj) throws Exception {
        Object value = field.get(obj);
        node.setTextContent(value == null ? "" : String.valueOf(value));
    }
}
